<template>
	<view class="my">
		<!-- 头部 -->
		<view class="title" @click="Ongoin">
			<image class="title_image" v-if="userInfo.nickname" :src="userInfo.headimgurl"></image>
			<image class="title_image" v-else src="../../static/my/portrait.png"></image>
			<view class="title_bos">
				<view class="title_box" v-if="userInfo.nickname">
					<view class="title_switch">
						<view class="font-323232 font-b font17">{{userInfo.nickname}}</view>
				<!-- 		<view class="switch_box" @click.stop="Ondoctor('doc')" v-if="userInfo.is_doctor==1">
							<image src="../../static/com/switch.png"></image>
							<text class="font-7d766b font14">切换到医生端</text>
						</view> -->
						<view class="switch_box" @click.stop="Ondoctor('business')">
							<image src="../../static/com/switch.png"></image>
							<text class="font-7d766b font14">切换到机构端</text>
						</view>
					</view>
					<view class="font-7d766b font14 flex-row-between">
						<view>就诊卡 <text class="font-6ccbb6">{{familynum}}</text> 张 </view>
					<!-- 	<view class="switch_box" @click.stop="Ondoctor('drug')" v-if="userInfo.is_pharmacist==1">
							<image src="../../static/com/switch.png"></image>
							<text class="font-7d766b font14">切换到药师端</text>
						</view> -->
					</view>
				</view>
				<view v-else class="font-323232 font-b font17">未登录</view>
			</view>
		</view>
		<!-- 就诊卡 -->
		<view class="medical" @click="Onmedical">
			<view class="medical_bos" v-if="familyobj.name&&userInfo.nickname">
				<view class="medical_left">
					<view class="medical_name font-ffffff font17">
						<text>{{familyobj.name}}</text>
						<view v-if="familyobj.is_default == 1">默认卡</view>
					</view>
					<view class="medical_card font-ffffff font12">
						就诊卡:{{familyobj.code}}
					</view>
				</view>
				<view class="medical_right font-6ccbb6 font14">切换</view>
			</view>
			<view @click.stop="goNext('/pagesA/my/jzrgladd',false)" class="medical_add font-ffffff font17 font-b" v-else>
				+ 添加就诊卡</view>
		</view>
		<!-- 边框 -->
		<view class="com_border"></view>
		<!-- 我的订单 -->
		<view class="order">
			<view v-for="(item,index) in orderList" :key="index" class="order_list" @click="goNext(item.url,false)">
				<image :src="item.img"></image>
				<view>{{item.title}}</view>
			</view>
		</view>
		<!-- 信息 -->
		<view class="information">
			<view v-for="(item,index) in informationList" :key="index" @click="goNext(item.url,item.url=='/pages/doctor/index'?true:false)">
				<view class="information_list" v-if="item.show">
					<image class="info_image" :src="item.img"></image>
					<view class="info_box">
						<view>{{item.title}}</view>
						<text>{{item.text}}</text>
					</view>
					<image class="info_morea" src="../../static/my/morea.png"></image>
				</view>
			</view>
		</view>
		<!-- -->
		<!-- 退出登录 -->
		<view class="signout" v-if="userInfo.nickname">
			<view class="signout_box" @click="Onlogout">退出登录</view>
		</view>
		<view class="signout_is" v-if="userInfo.nickname"></view>
		<!-- 就诊人弹窗 -->
		<uni-popup ref="popup" type="bottom">
			<view class="ComPopup_bos">
				<view class="popup_title">
					<view class="popup_time font15 font-323232 font-b">切换接诊人</view>
					<image @click="Onclose" class="popup_img" src="@/static/close.png"></image>
				</view>
				<view class="outpatient_pbos">
					<!-- 开始循环 -->
					<view class="outpatient_Popup" v-for="(item,index) in familyList" :key="index"
						@click="Ondefault(item)">
						<view class="outpatient_Popupbox">
							<text class="font17 font-323232"
								:class="item.id == familyobj.id?'font-b':''">{{item.the_patient_info.name}}</text>
							<image v-if="item.id == familyobj.id" class="outpatient_image" src="@/static/my/mor_b.png">
							</image>
						</view>
						<view class="outpatient_card font14 font-7d766b">就诊卡:{{item.the_patient_info.code}}</view>
					</view>
				</view>
				<!-- 按钮 -->
				<view class="ComPopup_button">
					<view @click="goNext('/pagesA/my/jzrgladd',false)">添加就诊人</view>
					<view @click="goNext('/pagesA/my/jzrgl',false)">就诊人管理</view>
				</view>
			</view>
		</uni-popup>
		<ComTabBar :selected="3"></ComTabBar>
	</view>
</template>

<script>
	import ComTabBar from '@/components/ComTabBar.vue';
	export default {
		components: {
			ComTabBar
		},
		data() {
			return {
				userInfo: {}, //用户信息
				familyobj: {}, //默认就诊人
				familynum: 0, //就诊人人数
				familyList: [], //就诊人列表
				//订单
				orderList: [{
					title: '缴费记录',
					img: require('@/static/my/order_a.png'),
					url: '/pagesA/my/paylist',
				},

				{
					title: '挂号列表',
					img: require('@/static/my/order_c.png'),
					url: '/pagesA/my/registerlist',
				},
				{
					title: '我的处方',
					img: require('@/static/doctor/info_c.png'),
					url: '/pagesA/prescript/order3',
				},
				{
					title: '药品订单',
					img: require('@/static/my/order_d.png'),
					url: '/pagesA/drug/list',
				},
				{
					title: '体检订单',
					img: require('@/static/my/order_b.png'),
					url: '/pagesA/check/list/list',
				}],
				//信息
				informationList: [
					{
						title: '图文问诊订单',
						img: require('@/static/doctor/info_a.png'),
						text: '',
						url: '/pagesA/my/textList/textList',
						show: true,
					},
					{
						title: '视频问诊订单',
						img: require('@/static/doctor/info_b.png'),
						text: '',
						url: '/pagesA/my/videoList/videoList',
						show: true,
					},
					{
						title: '就诊人管理',
						img: require('@/static/my/info_a.png'),
						text: '',
						url: '/pagesA/my/jzrgl',
						show: true,
					},
					{
						title: '体检人管理',
						img: require('@/static/my/order_e.png'),
						text: '',
						url: '/pagesA/check/listpeo/listpeo',
						show: true,
					},
					{
						title: '我的评论',
						img: require('@/static/my/comment.png'),
						text: '',
						url: '/pagesA/my/comment',
						show: true,
					},
					{
						title: '我的收藏',
						img: require('@/static/my/info_b.png'),
						url: '/pagesA/my/collect',
						text: '',
						show: true,
					}, {
						title: '收货地址',
						img: require('@/static/my/info_c.png'),
						text: '',
						url: '/pagesA/my/address',
						show: true,
					},
					{
						title: '切换到医生端',
						img: require('@/static/info/info_a.png'),
						text: '',
						url: '/pages/doctor/index',
						show: false,
					},
					{
						title: '切换到药师端',
						img: require('@/static/info/info_c.png'),
						text: '',
						url: '/pagesA/prescript/index',
						show: false,
					}
				]
			}
		},
		onShow: function() {
			//判断是否登录和显示的判断
			this.Oninfo()
			wx.hideTabBar()
		},
		methods: {
			Oninfo() {
				let token = uni.getStorageSync("token");
				let that = this
				//用户登录过
				if (token) {
					this.$Http({
						url: 'getUserInfo',
						type: 'POST',
						data: {}
					}).then(res => {
						if (res.code == 1) {
							this.userInfo = res.data
							uni.setStorage({
								key: 'userInfo',
								data: res.data,
								success: function() {
									//获取就诊人列表
									that.OnPatient()
									that.informationList.forEach(item=>{
										if(that.userInfo.is_doctor ==1){
											if(item.url == '/pages/doctor/index'){
												item.show = true
											}
										}
										if(that.userInfo.is_pharmacist ==1){
											if(item.url == '/pagesA/prescript/index'){
												item.show = true
											}
										}
									})
									// if(that.userInfo.is_doctor ==1){
									// 	that.informationList[6].show = true
									// }
									// if(that.userInfo.is_pharmacist ==1){
									// 	that.informationList[7].show = true
									// }
								}
							});
						}
					})
				} else {
					this.userInfo = {}
				}
			},
			//获取就诊人
			OnPatient() {
				this.$Http({
					url: 'listThePatient',
					data: {}
				}).then(res => {
					if (res.code == 1) {
						this.familynum = res.data.length
						if (!res.data || res.data.length == 0) {} else {
							this.familyList = res.data
							this.familyobj = res.data[0] ? res.data[0].the_patient_info : {}
							res.data.forEach(item => {
								item.the_patient_info.namea = item.the_patient_info.name.substring(item
									.the_patient_info.name.length - 2)
								if (item.isdefault == 1) {
									this.familyobj = item.the_patient_info
								}
							})
						}
					}
				})
			},
			//设置默认就诊人
			Ondefault(e) {
				if (e.id == this.familyobj.id) {
					this.$refs.popup.close()
					return
				}
				this.$Http({
					url: 'setDefaultThePatient',
					type: 'POST',
					show: true,
					data: {
						isdefault: 1,
						id: e.id
					}
				}).then(res => {
					if (res.code == 1) {
						this.OnPatient()
					}
					this.$refs.popup.close()
				})
			},
			//去登录
			Ongoin() {
				if (!this.userInfo.nickname) {
					uni.navigateTo({
						url: '/pagesA/common/Signin',
					})
				}
			},
			//切换接诊人弹窗
			Onmedical() {
				this.$refs.popup.open()
			},
			//关闭弹窗
			Onclose() {
				this.$refs.popup.close()
			},
			//前往医生端
			Ondoctor(e) {
				if (e == 'doc') {
					uni.switchTab({
						url: '/pages/doctor/index',
					})
				}else if (e == 'drug') {
					uni.navigateTo({
						url: '/pagesA/prescript/index',
					})
				}else if (e == 'business'){
					if(this.userInfo.is_business==1){
						uni.navigateTo({
							url: '/pagesB/business/index',
						})
					}else{
						uni.navigateTo({
							url: '/pagesB/business/apply',
						})
					}
				}
			},
			//退出登录
			Onlogout() {
				this.$store.dispatch('logout')
				// uni.clearStorage();
				this.userInfo = {}
			},
			// 路由跳转: tag默认false,tag=true跳到tabBar页面
			goNext(url, tag) {
				if (!this.userInfo.nickname) {
					uni.showToast({
						icon: 'none',
						duration: 2000,
						title: '请先登录'
					});
					return
				}
				if (url == '/pagesA/my/jzrgladd') {
					this.$store.commit('Onjzkurl', '/pages/my/index')
				}
				this.$refs.popup.close()
				if (tag) {
					uni.switchTab({
						url: url
					});
				} else {
					uni.navigateTo({
						url: url
					});
				}
			},
		}
	}
</script>

<style>
	page{
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}
	/* 头部 */
	.title {
		padding: 34rpx 34rpx 46rpx 34rpx;
		display: flex;
		align-items: center;
	}

	.title_image {
		width: 106rpx;
		height: 106rpx;
		border-radius: 30rpx;
		margin-right: 50rpx;
	}

	.title_box {
		height: 106rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
	}

	.title_switch {
		width: 526rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.switch_box {
		display: flex;
		align-items: center
	}

	.switch_box image {
		width: 36rpx;
		height: 36rpx;
		margin-right: 10rpx;
	}

	/* 就诊卡 */
	.medical {
		height: 150rpx;
		width: 682rpx;
		border-radius: 30rpx;
		background-color: #6ccbb6;
		margin-left: 34rpx;
		padding: 0 40rpx;
	}

	.medical_add {
		line-height: 150rpx;
	}

	.medical_bos {
		width: 602rpx;
		height: 150rpx;
		display: flex;
	}

	.medical_left {
		width: 480rpx;
		height: 150rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.medical_name {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.medical_name text {
		margin-right: 20rpx;
	}

	.medical_name view {
		padding: 3rpx 6rpx;
		border: 1rpx #fff solid;
		font-size: 24rpx;
		border-radius: 6rpx;
		margin-right: 10rpx;
	}

	.medical_right {
		background-color: #fff;
		width: 120rpx;
		height: 42rpx;
		border-radius: 30rpx;
		line-height: 42rpx;
		text-align: center;
		margin: auto;
	}

	/* 我的订单 */
	.order {
		height: 270rpx;
		width: 750rpx;
		display: flex;
		justify-content: space-around;
	}

	.order_list {
		padding-top: 100rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.order_list image {
		width: 70rpx;
		height: 70rpx;
		margin-bottom: 24rpx;
	}

	.order_list view {
		font-size: 26rpx;
		color: #323232;
	}

	/* 信息 */
	.information_list {
		height: 110rpx;
		width: 750rpx;
		padding: 0 40rpx;
		display: flex;
		align-items: center;
		border-bottom: 2rpx #f5f5f5 solid;
	}

	.information_list:last-child {
		border-bottom: 0rpx #f5f5f5 solid;
	}

	.info_image {
		height: 42rpx;
		width: 42rpx;
	}

	.info_morea {
		width: 13rpx;
		height: 24rpx;
	}

	.info_box {
		width: 612rpx;
		display: flex;
		justify-content: space-between;
		padding: 0 20rpx 0 30rpx;
	}

	.info_box view {
		font-size: 30rpx;
		color: #323232;
	}

	/* 退出登录 */
	.signout {
		height: 184rpx;
		width: 750rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	/* 	position: fixed;
		bottom: 120rpx;
		left: 0; */
	}

	.signout_is{
		height: 150rpx;
		width: 750rpx;
	}

	.signout_box {
		width: 655rpx;
		height: 85rpx;
		background-color: #f5f5f5;
		border-radius: 10rpx;
		font-size: 32rpx;
		color: #323232;
		line-height: 85rpx;
		text-align: center;
	}

	.my_border {
		width: 750rpx;
		height: 15rpx;
		background-color: #f9f9f9;
	}

	/* 弹窗 */
	.ComPopup_bos {
		background-color: #ffffff;
		border-radius: 30rpx 30rpx 0 0;
	}

	.popup_title {
		position: relative;
		width: 750rpx;
		height: 106rpx;
	}

	.popup_time {
		width: 750rpx;
		text-align: center;
		height: 106rpx;
		line-height: 106rpx;
	}

	.popup_img {
		height: 36rpx;
		width: 36rpx;
		position: absolute;
		top: 35rpx;
		right: 20rpx;
	}

	.outpatient_pbos {
		padding-top: 10rpx;
	}

	.outpatient_Popup {
		width: 750rpx;
		padding: 20rpx 30rpx;
		border-bottom: 1rpx #eeeeee solid;
	}

	.outpatient_Popupbox {
		display: flex;
		width: 690rpx;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 10rpx;
	}

	.outpatient_image {
		height: 30rpx;
		width: 30rpx;
	}

	.ComPopup_button {
		display: flex;
		width: 750rpx;
		height: 100rpx;
		color: #6ccbb6;
		font-size: 30rpx;
	}

	.ComPopup_button view:nth-of-type(1) {
		background-color: #6ccbb6;
		color: #ffffff;
	}


	.ComPopup_button view:nth-of-type(2) {
		background-color: #ffffff;
		color: #6ccbb6;
	}

	.ComPopup_button view {
		width: 50%;
		text-align: center;
		line-height: 100rpx;
	}
</style>
